package utils.view
{
	import flash.net.FileReference;
	
	import mx.containers.Panel;
	import mx.controls.Alert;
	import mx.messaging.messages.ErrorMessage;
	import mx.rpc.events.FaultEvent;
	
	import utils.EventAlert;
	import utils.SMContainerUtils;

	public class SMPanel extends Panel
	{
		public function SMPanel()
		{
		}
		
		public function syncronizedPanelByObject(jcValueObject:Object, excludeFields:Array = null) : *
		{
			return SMContainerUtils.syncronizedContainerForObject(jcValueObject, this, excludeFields);
		}
		
		public function syncronizedObjectByPanel(jcValueObject:Object, excludeParameters:Array = null) : *
		{
			return SMContainerUtils.syncronizedObjectForContainer(jcValueObject, this, excludeParameters);
		}
		
		public function validationAndSyncronizedObject(jcValueObject:Object, excludeParameters:Array = null) : *
		{
			if (validationRequiredFields())
			{
				return syncronizedObjectByPanel(jcValueObject, excludeParameters);
			}
		}
		
		public function validationRequiredFields(excludeFields:Array = null) : Boolean
		{
			
			var retorno:Boolean = SMContainerUtils.validationRequiredFieldsByContainer(this, excludeFields);
			
			if (!retorno)
			{
				Alert.show('Campos obrigatórios não preenchidos!', 'Validação');
			}
			
			return retorno;
			
		}
		
		public function clearFields(excludeFields:Array = null) : void
		{
			SMContainerUtils.clearFieldsByPanel(this, excludeFields);
		}
		
		public function handleException(event:FaultEvent):void{
			var errorMessage:ErrorMessage = event.message as ErrorMessage;
			EventAlert.showErrorTitle(errorMessage.rootCause.message, 'Atenção');
		}
		
	}
}